As is well known, Java™ is an object-oriented programming environment developed and distributed by Sun Microsystems. Java is capable of generating applications which may be executed on any Java-enabled platform. In the Java environment, a proxy is an object which acts as a surrogate for the underlying (“real”) object and filters or modifies messages from the client before forwarding them to the real object. The proxy is typically transparent to the client by implementing interfaces of the real object. In early versions of Java, proxies were defined only by programming convention and fixed at compile time. However, a recent release of Java, version 1.3, introduced the Dynamic Proxy API through which proxy classes and objects may instead be assembled and dynamically reconfigured “on-the-fly” at runtime.
As illustrated in FIG. 1, an invocation of a dynamic proxy method is a synchronous method call. A client 10 requests that the runtime 20 create a dynamic proxy for a real interface (step 100). The runtime creates (step 102) and returns (step 104) the dynamic proxy. When the client 10 invokes a method on the proxy object (step 106), the runtime invokes the method on the target object 30 (step 108). Upon completion of the method, the target object 30 returns the results (step 110) to the runtime 20 which returns the results to the client (step 112). Until the results are returned to the client 10, the client 10 is effectively blocked from further activities, including additional calls to the runtime 20.
The following is an exemplary coding of the creation and invoking of a synchronous proxy interface:
Service Interface:public interface originalInterface {public void getValue( );public void foo( ) throws Exception;}Target Object implements this interface for clients to invoke.A Client invokes method of a target object as following:// synchronous case (client-side code)[normal case as described in Java 1.3]OriginalInterface proxy = (OriginalInterface)Proxy.newProxyInstance(classLoader, OriginalInterface.class,invocationHandler);int value = proxy.getValue( );
A technique has been developed for asynchronously invoking a method call, thereby allowing the client 10 to perform other activities until the call is returned. Such a technique, however, requires redefining the original interface to support asynchronous invocation. Thus, both the client and real object implementations must be changed. Consequently, a need remains for a technique to efficiently and dynamically invoke methods asynchronously.